package com.ts.core.controller;


import com.ts.core.entity.LxbArticle;
import com.ts.core.entity.Vo.ArticleVo;
import com.ts.core.entity.Vo.DetailVo;
import com.ts.core.entity.queryVo.ArticleQueryVo;
import com.ts.core.service.LxbArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 帖子 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2024-03-25
 */
@Api(tags = "帖子管理")
@RestController
@RequestMapping("/admin/core/article")

public class LxbArticleController {

    @Resource
    private LxbArticleService lxbArticleService;

    @GetMapping("list")
    public Map<String,Object> getAllFromTable(){
      List<ArticleVo> list= lxbArticleService.getAll();
        HashMap<String, Object> map = new HashMap<>();
        map.put("code","0");
        map.put("message","获取成功");
        HashMap<String, Object> data = new HashMap<>();
        data.put("list",list);
        map.put("data",data);
        return  map;
    }

    @ApiOperation("根据id逻辑删除帖子")
    @GetMapping("delete/{id}")
    public Map<String,Object> DeleteById(
            @PathVariable String id
    ){
        boolean b = lxbArticleService.removeById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("code","0");
        if(b)
        {

            map.put("message","删除成功");


        }
        else{
            map.put("message","删除成功");

        }
        return  map;

    }

    @ApiOperation("根据条件查询")
    @PostMapping("query")
    public Map<String,Object> selectByCondition
            (
            @RequestBody ArticleQueryVo articleQueryVo
            ){

        List<ArticleVo> list= lxbArticleService.selectList(articleQueryVo);
        HashMap<String, Object> map = new HashMap<>();
        map.put("code","0");
        map.put("message","查找成功");
        HashMap<String, Object> data = new HashMap<>();
        data.put("list",list);
        map.put("data",data);
        return map;
    }

    @ApiOperation("根据id更改审核状态")
    @GetMapping("update/{id}")
    public Map<String,Object> UpdateStateById(
            @PathVariable String id
    ){
        lxbArticleService.updateStateById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("code","0");
        map.put("message","审核通过");
        return map;


    }

    @ApiOperation("根据id获取帖子的详情")
    @GetMapping("getdatail/{id}")
    public Map<String,Object> getDetail(
            @PathVariable String id
    ){
       DetailVo detailVo= lxbArticleService.getDetail(id);





        HashMap<String, Object> map = new HashMap<>();
        map.put("code","0");
        map.put("message","查找成功");
        HashMap<String, Object> data = new HashMap<>();
        data.put("list",detailVo);
        map.put("data",data);
        return map;
    }
}

